"""
@文件: admin.py
@Author: ZJJ
@Email: 1065377805@qq.com
@Time: 2025/3/7
@Des:schemas模型
"""
from datetime import datetime
from typing import Optional, List

from pydantic import BaseModel, Field
from pydantic.v1 import validator

from schemas.base import BaseResp, ResAntTable


class CreateAdmin(BaseModel):
    username: str = Field(min_length=3, max_length=10)
    password: str = Field(min_length=6, max_length=12)
    nickname: str = Field(min_length=1, max_length=20)
    full_name: str = Field(min_length=1, max_length=20)
    user_type: bool
    user_phone: Optional[str] = Field(pattern="^1[34567890]\\d{9}$")
    user_status: Optional[bool]
    remarks: Optional[str]
    roles: Optional[List[int]]

class UpdateAdmin(BaseModel):
    username: Optional[str] = Field(min_length=3, max_length=10)
    password: Optional[str] = Field(min_length=6, max_length=12)
    user_phone: Optional[str] = Field(pattern="^1[34567890]\\d{9}$")
    user_status: Optional[bool]

class AccountLogin(BaseModel):
    username: Optional[str] = Field(min_length=3, max_length=10, description="用户名")
    password: Optional[str] = Field(min_length=6, max_length=12, description="密码")
    # mobile: Optional[str] = Field(regex="^1[34567890]\\d{9}$", description="手机号")
    # captcha: Optional[str] = Field(min_length=6, max_length=6, description="6位验证码")


class SetRole(BaseModel):
    user_id:int
    role:Optional[List[int]] = Field(default=[],description="角色")

class AdminInfo(BaseModel):
    username: str
    # age: Optional[int]
    user_type: bool
    nickname: Optional[str]
    user_phone: Optional[str]
    user_email: Optional[str]
    full_name: Optional[str]
    scopes: Optional[List[str]]
    user_status: bool
    header_img: Optional[str]
    sex: int

class UserListItem(BaseModel):
    key: int
    id: int
    username: str
    # age: Optional[int]
    user_type: bool
    nickname: Optional[str]
    user_phone: Optional[str]
    user_email: Optional[str]
    full_name: Optional[str]
    user_status: bool
    header_img: Optional[str]
    sex: int
    remarks: Optional[str]
    create_time: datetime
    update_time: datetime



class AccessToken(BaseModel):
    token:Optional[str]
    expires_in:Optional[int]

class UserListData(ResAntTable):
    data: List[UserListItem]

class AdminLogin(BaseResp):
    data:AccessToken

class CurrentAdmin(BaseResp):
    data:AdminInfo

class UpdateAdminInfo(BaseModel):
    nickname: Optional[str]
    user_email: Optional[str]
    header_img: Optional[str]
    user_phone: Optional[str] = Field(pattern="^1[34567890]\\d{9}$", description="手机号")
    password: Optional[str] = Field(min_length=6, max_length=12, description="密码")

    @validator('*')
    def blank_strings(cls, v):
        if v == "":
            return None
        return v